package com.dragon.annotation;

import java.util.List;

/**
 * @author dragon
 * @since 2019/12/3
 */
public class TableGenerator {

    private static PackageScanner packageScanner;

    private static GenSql genSql;

    private static ExecuteSql executeSql;

    private static Parser parser;

    static {
        packageScanner = new DefaultPackageScanner();
        genSql = new DefaultGenSql();
        executeSql = new DefaultExecuteSql();
        parser = new DefaultParser();
    }

    private TableGenerator() {

    }

    public static void tableGenerator(Class<?> annotatedClasses) {
        try {
            List<Class<?>> classes = packageScanner.scanPackage(annotatedClasses);
            List<EntityTable> entityTableList = parser.parse(classes);
            String sql = genSql.generateSql(entityTableList);
            executeSql.execute(sql);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
